<?php
/**
 * Created by PhpStorm.
 * User: dumbledore
 * Date: 2018/3/12
 * Time: 上午9:52
 */
?>
<!DOCTYPE html>
<html>
<head>
    <!--[if lt IE 7]>
    <div class="ie6_error">还在用<strong>漏洞百出的IE6浏览器</strong>么？为了您的网络安全，请升级浏览器 <a target="_blank"
                                                                               href="http://browsehappy.com">立即升级</a>
    </div>
    <![endif]-->
    <meta charset="utf-8">
    <title>用户账户-文具1号</title>
    <meta name="description"
          content="文具1号作为上海办公用品供货商公司,专为世界500强企业及SOHO办公族提供网上商城一站式办公耗材批发及采购服务,一站式选购办公日用文具用品,厂家直销,好货又便宜【阳光采购就上文具1号 阳光价格 老板放心 品质保障 员工省力】"/>
    <meta name="keywords" content="办公用品,办公文具,办公文具网站,文具网站,办公用品网,文具采购网,金万年"/>
    <meta name="copyright" content="上海易推信息科技有限公司"/>
    <meta name="renderer" content="webkit">
    <base href="<?php echo base_url(); ?>"/>
    <link rel="shortcut icon" href="favicon.ico"/>
    <link rel="stylesheet" href="public/js/layui/css/layui.css">
    <link rel="stylesheet" type="text/css" href="public/css/base.css"/>
    <link rel="stylesheet" type="text/css" href="public/css/common.css"/>
    <link rel="stylesheet" type="text/css" href="public/css/index.css"/>
    <link type="text/css" rel="stylesheet" href="public/css/owl.carousel.css">
    <link type="text/css" rel="stylesheet" href="public/css/owl.theme.css">
</head>
<body>
<?php $this->load->view('common/header.php'); ?>

<div class="container mt20 bg-padding-inside">
    <div class="user-account-container">
        <div class="user-account-title-wrapper">
            <p class="path-tit">
                <em class="color-red">首页</em>＞用户账户
                <a href="<?php echo base_url(); ?>cost_center/cost_center_user_present"
                   class="path-tit-link">(什么是用户账户？）</a>
            </p>
            <a href="<?php echo base_url(); ?>cost_center/create_user_index" class="create-user-account-btn">
                + 创建用户账号
            </a>
            <div class="user-account-search-input-wrapper">
                <span class="icon-search bg-icon_search_grey" style="cursor: pointer;"></span>
                <input class="user-account-search-input" type="text" id="username" placeholder="搜索用户账户">
            </div>
        </div>
        <div class="user-account-table-box">
            <table border="1" class="user-account-tab">
                <thead>
                <tr>
                    <th>序号</th>
                    <th>成本中心</th>
                    <th>所属管理账户</th>
                    <th>账户</th>
                    <th>联系人</th>
                    <th>联系方式</th>
                    <th>单品预算(元)</th>
                    <th>预算(元)</th>
                    <th>已使用</th>
                    <th>可使用</th>
                    <th>限定清单</th>
                    <th></th>
                </tr>
                </thead>
                <tbody>
                <tr>

                </tr>
                <?php if (isset($user)): ?>
                    <?php foreach ($user as $key => $adm): ?>
                        <tr>
                            <td> <?php echo $key + 1 ?></td>
                            <?php if (isset($adm['cost_center'])): ?>
                                <td id="name" title="<?php echo $adm['cost_center']['name'] ?>"><?php echo mb_substr($adm['cost_center']['name'], 0,5) ?><?php if(mb_substr($adm['cost_center']['name'],0,12) != $adm['cost_center']['name']):?>...<?php endif;?></td>
 
                            <?php else: ?>
                                <td>无</td>
                            <?php endif; ?>
                            <?php if (isset($adm['pusername'])): ?>
                                <td>
                                    <a href="<?php echo base_url('cost_center/manager_user_edit'); ?>?id=<?php echo $adm['parent_id']; ?>" title="<?php echo $adm['pusername']['username']?>"><?php echo mb_substr($adm['pusername']['username'], 0,12) ?><?php if(mb_substr($adm['pusername']['username'],0,12) != $adm['pusername']['username']):?>...<?php endif;?></a>
                                </td>
                            <?php else: ?>
                                <td>无</td>
                            <?php endif; ?>
                            <td>
                                <a href="<?php echo base_url('cost_center/manager_user_edit'); ?>?id=<?php echo $adm['id']; ?>" title="<?=$adm['username']?>"><?php echo mb_substr($adm['username'],0,12) ?><?php if(mb_substr($adm['username'],0,12) != $adm['username']):?>...<?php endif;?></a>
                            </td>
                            <td><?php echo $adm['name'] ?> </td>
                            <td><?php echo $adm['tel'] ?> </td>
                            <?php if (isset($adm['manager_user'])): ?>
                                <td>￥<?php echo $adm['manager_user']['single_quota'] ?> (元)</td>
                            <?php else: ?>
                                <td>0</td>
                            <?php endif; ?>
                            <?php if (isset($adm['budgets'])): ?>
                                <td>￥<?php echo $adm['budgets']['budget']; ?>(元)</td>
                                <td>￥<?php echo $adm['budgets']['used']; ?>(元)</td>
                                <td>￥<?php echo $adm['budgets']['budget'] - $adm['budgets']['used'] ?>(元)</td>
                            <?php else: ?>
                                <td>0</td>
                                <td>0</td>
                                <td>0</td>
                            <?php endif; ?>
                            <?php foreach ($datas as $key => $da): ?>
                                <?php if ($key == $adm['id']): ?>
                                    <?php if (count($da)): ?>
                                        <td><?php echo count($da); ?> 个</td>
                                    <?php else: ?>
                                        <td>0 个</td>
                                    <?php endif; ?>
                                    <td>
                                        <?php if (isset($da) && count($da)): ?>
                                        <div class="user-account-table-list-more">
                                            <a href="javascript:;" class="icon-more bg-btn_more_n"></a>
                                            <div class="show-more bg-bg_pop dn">
                                                    <div class="show-more-cont">
                                                        <?php foreach ($da as $ke => $das): ?>
                                                            <a class="text-ellipsis" target="_blank"
                                                               href="<?php echo $this->config->item('shop_url'); ?>mMPur-detaillist.html&pkey=<?php echo $ke; ?>"><?php echo $das ?>
                                                            </a>
                                                        <?php endforeach; ?>
                                                    </div>
                                            </div>
                                        </div>
                                        <?php endif; ?>
                                    </td>
                                <?php endif; ?>
                            <?php endforeach; ?>
                        </tr>
                    <?php endforeach; ?>
                <?php endif; ?>

                </tbody>
            </table>
            <!--<table class="layui-hide" id="test"></table>-->
        </div>
    </div>
</div>

<?php $this->load->view('common/bottom.php'); ?>
<script type="text/javascript" src="public/js/jquery.min.js"></script>
<script type="text/javascript" src="public/js/index.js"></script>
<script src="public/js/layui/layui.js"></script>
<script type="text/javascript" src="public/js/owl.carousel.min.js"></script>
<script type="text/javascript">
    $(function () {

        $("body").on('hover', '.icon-more', function () {
            $(this).next().show();
//      $(this).toggleClass('icon-more_hover');
        });
        $("body").on('hover', '.show-more', function () {
            $(this).parent().find(".icon-more").addClass('icon-more_hover');
        }, function () {
            $(this).parent().find(".icon-more").removeClass('icon-more_hover');
        });
        $("body").on('mouseleave', '.show-more', function () {
            $(this).parent().find(".show-more").hide();
        });
        $("body").on('keypress', '#username', function (event) {
            if (event.keyCode == "13") {
                var username = $('#username').val();
                query_user_list({'username': username})
            }
        });
        $('.bg-icon_search_grey').click(function(){
            var username= $('#username').val();
            $.ajax({
                type: "POST",
                url: "index/index_user_manage",
                data: {username:username},
                dataType: "json",
                async: true,
                success: function (data) {
                    var user = data.data;
                    // console.log(data.data);
                    if (data.code == 0) {
                        var html = '';
                        html += ' <tr>';
                        html += '  </tr>';
                        if (user != '') {
                            $(user).each(function (key, val) {
                                var id = key + 1;
                                html += ' <tr>';
                                html += '   <td> ' + id + '</td>';
                                if (val.cost_center != '') {
                                    html += '<td id="name">' + val['cost_center']['name'] + '</td>';
                                } else {
                                    html += '<td>无</td>';
                                }
                                if (!val.pusername ) {
                                        html += '<td>无</td>';
                                }else {
                                    html += '<td id="name"><a href="cost_center/manager_user_edit/?id=' + val.pusername["id"] + '">' + val.pusername['username'] + '</a></td>';
                                }

                                html += '   <td ><a href="cost_center/manager_user_edit/?id='+ val['id'] +'"> ' + val['username'] + '</a> </td>';
                                html += '  <td>' + val.name + ' </td>';
                                html += '  <td>' + val.tel + ' </td>';
                                if (val.manager_user != '') {
                                    html += ' <td>￥' + val.manager_user['single_quota'] + ' (元)</td>';
                                } else {
                                    html += '  <td>0</td>';
                                }
                                if (val.budgets != '') {
                                    var used = val.budgets['used'];
                                    var budget = val.budgets['budget'];
                                    var con = budget - used;
                                    html += ' <td>￥' + val.budgets['budget'] + ' (元)</td>';
                                    html += ' <td>￥' + val.budgets['used'] + ' (元)</td>';
                                    html += ' <td>￥' + con + ' (元)</td>';
                                } else {
                                    html += '  <td>0</td>';
                                    html += '  <td>0</td>';
                                    html += '  <td>0</td>';
                                }
                                if (val.totals != '') {
                                    html += '   <td>' + val.totals + '个 </td>';
                                } else {
                                    html += '   <td>0件 </td>';
                                }
                                html += '  <td>';
                                if (val.datas != '') {
                                html += '  <div class="user-account-table-list-more">';
                                html += '  <a href="javascript:;" class="icon-more bg-btn_more_n"></a>';
                                html += '  <div class="show-more bg-bg_pop dn">';

                                    var datas = val.datas;
                                    html += '<div class="show-more-cont">';
                                    $.each(datas, function (k, v) {
                                        html += '<a class="text-ellipsis" target="_blank"  href="<?php echo $this->config->item('shop_url'); ?>mMPur-detaillist.html&pkey=' + k + '"  >' + v + '…</a>';
                                    })
                                    for (va in datas) {
                                        //html += '<a class="text-ellipsis" target="_blank"  href="<?php echo $this->config->item('shop_url'); ?>mMPur-detaillist.html&pkey=' + datas[va]['goods_id'] +'"  >' + datas[va]['goods_name'] + '…</a>';
                                    }
                                    html += '</div>';

                                html += '   </div>';
                                html += '  </div>';
                                }
                                html += '   </td>';
                                html += '   </tr>';
                            });
                            // console.log(html);
                            $("tbody").html(html);

                        }
                    } else {
                        $("tbody").html('');
                    }
                }
            });
        });

        function query_user_list(data) {
            $.ajax({
                type: "POST",
                url: "index/index_user_manage",
                data: data,
                dataType: "json",
                async: true,
                success: function (data) {
                    var user = data.data;
                    // console.log(data);
                    if (data.code == 0) {
                        var html = '';
                        html += ' <tr>';
                        html += '  </tr>';
                        if (user != '') {
                            $(user).each(function (key, val) {
                                var id = key + 1;
                                html += ' <tr>';
                                html += '   <td> ' + id + '</td>';
                                if (val.cost_center != '') {
                                    html += '<td id="name">' + val['cost_center']['name'] + '</td>';
                                } else {
                                    html += '<td>无</td>';
                                }
                                if (!val.pusername ) {
                                        html += '<td>无</td>';
                                }else {
                                    html += '<td id="name"><a href="cost_center/manager_user_edit/?id=' + val.pusername["id"] + '">' + val.pusername['username'] + '</a></td>';
                                }
                                html += '   <td ><a href="cost_center/manager_user_edit/?id='+ val["id"] +'"> ' + val['username'] + '</a> </td>';
                                html += '  <td>' + val.name + ' </td>';
                                html += '  <td>' + val.tel + ' </td>';
                                if (val.manager_user != '') {
                                    html += ' <td>￥' + val.manager_user['single_quota'] + ' (元)</td>';
                                } else {
                                    html += '  <td>0</td>';
                                }
                                if (val.budgets != '') {
                                    var used = val.budgets['used'];
                                    var budget = val.budgets['budget'];
                                    var con = budget - used;
                                    html += ' <td>￥' + val.budgets['budget'] + ' (元)</td>';
                                    html += ' <td>￥' + val.budgets['used'] + ' (元)</td>';
                                    html += ' <td>￥' + con + ' (元)</td>';
                                } else {
                                    html += '  <td>0</td>';
                                    html += '  <td>0</td>';
                                    html += '  <td>0</td>';
                                }
                                if (val.totals != '') {
                                    html += '   <td>' + val.totals + '个 </td>';
                                } else {
                                    html += '   <td>0件 </td>';
                                }
                                html += '  <td>';
                                if (val.datas != '') {
                                html += '  <div class="user-account-table-list-more">';
                                html += '  <a href="javascript:;" class="icon-more bg-btn_more_n"></a>';
                                html += '  <div class="show-more bg-bg_pop dn">';
                                    var datas = val.datas;
                                    html += '<div class="show-more-cont">';
                                    $.each(datas, function (k, v) {
                                        html += '<a class="text-ellipsis" target="_blank"  href="<?php echo $this->config->item('shop_url'); ?>mMPur-detaillist.html&pkey=' + k + '"  >' + v + '…</a>';
                                    })
                                    for (va in datas) {
                                        //html += '<a class="text-ellipsis" target="_blank"  href="<?php echo $this->config->item('shop_url'); ?>mMPur-detaillist.html&pkey=' + datas[va]['goods_id'] +'"  >' + datas[va]['goods_name'] + '…</a>';
                                    }
                                    html += '</div>';
                                html += '   </div>';
                                html += '  </div>';
                                }
                                html += '   </td>';
                                html += '   </tr>';
                            });
                            // console.log(html);
                            $("tbody").html(html);

                        }
                    } else {
                        $("tbody").html('');
                    }
                }
            });
        }
    });
</script>
</body>
</html>



